define
(    
    function()
    {
        return function(io, app, config)
        {            
            var express  = require('express'); 
            setupWebServer();

            function setupWebServer()
            {
                setupSessionStore();
                setupStaticContent();
                setupRoutes();
            }

            function setupSessionStore()
            {
                var MemoryStore = express.session.MemoryStore;
                var sessionStore = new MemoryStore();

                app.use(express.cookieParser());
                app.use(express.session({store: sessionStore, secret: 'secret', key: 'express.sid'}));
                app.use(app.router);
                
                var cookie = require('cookie');
                io.set('authorization', function (data, accept) 
                {                    
                    if (data.headers.cookie) 
                    {                        
                        data.cookie = cookie.parse(data.headers.cookie);                      
                        data.sessionID = data.cookie['express.sid'];
                    } 
                    else 
                    {
                       return accept('No cookie transmitted.', false);
                    }
                    
                    accept(null, true);
                });
            }

            function setupStaticContent()
            {                
                for (var folderIndex in config.content)
                {
                    var folder = config.content[folderIndex];
                    app.use("/" + folder, express.static(config.wwwRoot + folder));
                }
            }
            
            function setupRoutes()
            {
                for (var routeIndex in config.routes)
                {
                    var route = config.routes[routeIndex];
                    var handlerType = requirejs(route.handler);
                    var handler = new handlerType();
                    var regex = new RegExp(config.routes[routeIndex].regex);
                    bindRoute(regex, handler);
                }
            }

            function bindRoute(regex, handler)
            {                
                app.get(regex, function(req, res)
                {                                                
                    handler.handleRequest(req, res, config);
                });
            }
        }        
    }
);